using SoftFloat;

namespace Tests
{
    public class Tests
    {
        [SetUp]
        public void Setup()
        {
        }

        [Test]
        public void TestFloor()
        {
            Console.WriteLine($"MathF.Floor: {MathF.Floor(3.7f)}");
            Console.WriteLine($"MathF.Floor: {MathF.Floor(-3.7f)}");
            Console.WriteLine($"MathF.Floor: {MathF.Floor(3.4f)}");
            Console.WriteLine($"MathF.Floor: {MathF.Floor(-3.4f)}");

            Console.WriteLine($"libm.Floor: {libm.Floor(3.7f)}");
            Console.WriteLine($"libm.Floor: {libm.Floor(-3.7f)}");
            Console.WriteLine($"libm.Floor: {libm.Floor(3.4f)}");
            Console.WriteLine($"libm.Floor: {libm.Floor(-3.4f)}");
        }

        [Test]
        public void TestIEEERemainder() 
        {
            double dividend1 = 5.3;
            double divisor1 = 2.0;
            double dividend2 = -5.3;
            double divisor2 = 2.0;

            // 使用 Math.IEEERemainder 方法
            double result1 = Math.IEEERemainder(dividend1, divisor1);
            double result2 = Math.IEEERemainder(dividend2, divisor2);

            double result11 = libm.IEEERemainder(dividend1, divisor1);
            double result21 = libm.IEEERemainder(dividend2, divisor2);

            Console.WriteLine($"Math.IEEERemainder({dividend1}, {divisor1}) = {result1}"); // 输出: 1.3
            Console.WriteLine($"Math.IEEERemainder({dividend2}, {divisor2}) = {result2}"); // 输出: -1.3

            Console.WriteLine($"libm.IEEERemainder({dividend1}, {divisor1}) = {result11}"); // 输出: 1.3
            Console.WriteLine($"libm.IEEERemainder({dividend2}, {divisor2}) = {result21}"); // 输出: -1.3
        }

        [Test]
        public void TestTan() 
        {
            float angle = 45.0f;
            float tangentValue = MathF.Tan(angle);
            sfloat tangentValue1 = libm.Tan(angle);
            Console.WriteLine($"Math.Tan({angle} degrees) = {tangentValue}"); // 输出: 1
            Console.WriteLine($"libm.Tan({angle} degrees) = {tangentValue1}"); // 输出: 1
        }

        [Test]
        public void TestCeiling() 
        {
            float[] testValues = { 1.2f, 2.5f, -1.5f, -2.0f, 3.0f };

            foreach (var value in testValues)
            {
                float ceilingValue = MathF.Ceiling(value);
                sfloat ceilingValue1 = libm.Ceiling(value);
                Console.WriteLine($"Math.Ceiling({value}) = {ceilingValue}");
                Console.WriteLine($"libm.Ceiling({value}) = {ceilingValue1}"); //-1.5f 有毛病
            }
        }

        [Test]
        public void TestLog() 
        {
            float[] testValues = { 1.0f, 2.718f, 10.0f, 0.5f };

            foreach (var value in testValues)
            {
                float naturalLog = MathF.Log(value);
                sfloat naturalLog1 = libm.Log(value);
                Console.WriteLine($"MathF.Log({value}) = {naturalLog}");
                Console.WriteLine($"libm.Log({value}) = {naturalLog1}");
            }

            // 计算以10为底的对数
            float logBase10 = MathF.Log(100.0f, 10.0f);
            sfloat logBase101 = libm.Log(100.0f, 10.0f);
            Console.WriteLine($"MathF.Log(100, 10) = {logBase10}");
            Console.WriteLine($"libm.Log(100, 10) = {logBase101}");
        }

        [Test]
        public void TestPow() 
        {
            float[] bases = { 2.0f, 3.0f, 4.0f };
            float[] exponents = { 3.0f, 0.5f, -2.0f };

            foreach (var baseValue in bases)
            {
                foreach (var exponent in exponents)
                {
                    float result = MathF.Pow(baseValue, exponent);
                    sfloat result1 = libm.Pow(baseValue, exponent);
                    Console.WriteLine($"MathF.Pow({baseValue}, {exponent}) = {result}");
                    Console.WriteLine($"libm.Pow({baseValue}, {exponent}) = {result1}");
                }
            }
        }

        [Test]
        public void TestExp() 
        {
            float[] testValues = { 0.0f, 1.0f, 2.0f, -1.0f, 10.0f };

            foreach (var value in testValues)
            {
                float result = MathF.Exp(value);
                sfloat result1 = libm.Exp(value);
                Console.WriteLine($"MathF.Exp({value}) = {result}");
                Console.WriteLine($"libm.Exp({value}) = {result1}");
            }
        }
    }
}